import request from '@/utils/request'

// 获取任务配置列表
export function getTaskConfigs() {
  return request({
    url: '/dk/assistant/task-configs',
    method: 'get',
  })
}

// 创建任务配置
export function createTaskConfig(data) {
  return request({
    url: '/dk/assistant/task-config',
    method: 'post',
    data,
  })
}

// 获取API函数列表
export function getApiFunctions(taskConfigId) {
  return request({
    url: `/dk/assistant/api-functions/${taskConfigId}`,
    method: 'get',
  })
}

// 获取所有API函数列表（用于管理界面）
export function getAllApiFunctions(params = {}) {
  return request({
    url: '/dk/assistant/api-functions',
    method: 'get',
    params,
  })
}

// 创建API函数配置
export function createApiFunction(data) {
  return request({
    url: '/dk/assistant/api-config',
    method: 'post',
    data,
  })
}

// 更新API函数配置
export function updateApiFunction(id, data) {
  return request({
    url: `/dk/assistant/api-config/${id}`,
    method: 'put',
    data,
  })
}

// 删除API函数配置
export function deleteApiFunction(id) {
  return request({
    url: `/dk/assistant/api-config/${id}`,
    method: 'delete',
  })
}

// 测试API函数
export function testApiFunction(id, params = {}) {
  return request({
    url: `/dk/assistant/api-test/${id}`,
    method: 'post',
    data: { params },
  })
}

// 获取API函数详情
export function getApiFunctionDetail(id) {
  return request({
    url: `/dk/assistant/api-config/${id}`,
    method: 'get',
  })
}

// 启用/禁用API函数
export function toggleApiFunction(id, isActive) {
  return request({
    url: `/dk/assistant/api-config/${id}/toggle`,
    method: 'patch',
    data: { is_active: isActive },
  })
}

// 批量删除API函数
export function batchDeleteApiFunctions(ids) {
  return request({
    url: '/dk/assistant/api-functions/batch-delete',
    method: 'delete',
    data: { ids },
  })
}

// 导出API函数配置
export function exportApiFunctions(ids = []) {
  return request({
    url: '/dk/assistant/api-functions/export',
    method: 'post',
    data: { ids },
    responseType: 'blob',
  })
}

// 导入API函数配置
export function importApiFunctions(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/dk/assistant/api-functions/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}